package rlm.helper;

import java.awt.Component;
import java.awt.Rectangle;

import javax.swing.JComponent;

import rlm.rlcontainer.PlaceHolder;

/**
 * 
 * This example no longer works!!
 * To make it work, getComponent in PlaceHolder should be made public
 * 
 * 
 * created on 11:42:40 PM
 * @author robot
 */
public class Switcher extends Pair<PlaceHolder, PlaceHolder>{
	
	public Switcher(PlaceHolder from, PlaceHolder to){
		super(from,to);
	}
	
	public PlaceHolder getSource(){
		return super.getOne();
	}
	
	public PlaceHolder getTarget(){
		return super.getTwo();
	}

	
	public void apply(){
		Component a = getSource().getComponent();
		Component b = getTarget().getComponent();
		
		Rectangle boundsA = a.getBounds();
		Rectangle boundsB = b.getBounds();
		
		b.setBounds(boundsA);
		a.setBounds(boundsB);
		getSource().setComponent((JComponent) b);
		getTarget().setComponent((JComponent) a);
		
	}
}
